string.split = function(s, p)
    local rt= {}
    string.gsub(s, '[^'..p..']+', function(w) table.insert(rt, w) end )
    return rt
end

function GetPath(path,cmd)
  local subPath= string.split(path, '\\')
  local subCmd= string.split(cmd, '/')
  local e = #subPath
  local s = 1
  for _,v in pairs(subCmd) do
  	if v==".." then
  		e=e-1
  		s=s+1
  	end
  end
  local  newPath = ""
  for i=1,e,1 do
  	newPath=newPath..subPath[i].."\\"
  end
  for j=s,#subCmd,1 do
  	newPath=newPath..subCmd[j].."\\"
  end
  return  newPath
end


require("luacom")--引用com插件
require('lfs')    --导入lfs模块用于取得当前路径，和操作EXCEL无关
local JsonParser=require("jsonParser")

suffix=".lua"
local path = lfs.currentdir()    --取得当前路径 
path=GetPath(path,"..")

exportSheetName=1
exportIsY=2
exportCmd=3
exportDataStart=5
exportDataEnd=6
exportSubPath=7
exportMode=8
exportFileName=9
fileRootPath=""

jsonPath = "../Data/json/"

--[[ 创建excel对象 ----------]]
excel = luacom.CreateObject("Excel.Application") --创建新的实例

EggEexcel = excel.WorkBooks:Open(path .. '\\SubExcel\\Egg.xls', 0, 0)    --打开EXCEL文件，应使用绝对路

DATASheet = book.Sheets("DATA")    --数据表



-- -- #x,下，y横
-- -- 生成关卡数据

-- local perfabLoop={"lv_left_0","lv_left_1","lv_left_2","lv_left_3","lv_left_4"}
-- local p14="lv_left_14"
-- local p16="lv_left_16"

-- local LvXStart=6
-- local petfab12=1
-- function FullOneLevel(levelId,reword,awakeCondition,awakeReward,drop,nextCondition,monster,boxCount)
-- 		DATASheet.Cells(LvXStart, 4).Value2=levelId
-- 		local count=#monster
-- 		local path
-- 		local lenght=count+2*boxCount
-- 		if lenght<15 then 
-- 			path=perfabLoop[petfab12]
-- 			petfab12=petfab12+1
-- 			if petfab12>#perfabLoop then
-- 				petfab12=1
-- 			end
-- 		elseif lenght<16 then
-- 			path=p14
-- 		else
-- 			path=p16
-- 		end
-- 		LevelSheet.Cells(LvXStart, 1).Value2="DATA"
-- 		LevelSheet.Cells(LvXStart, 4).Value2=levelId
-- 		LevelSheet.Cells(LvXStart, 5).Value2=path

-- 		local str= ""
-- 		for i=1,count-1 do
-- 				str=str..monster[i]..","
-- 		end
-- 		str=str..monster[count]
-- 		LevelSheet.Cells(LvXStart, 6).Value2=str
-- 		LevelSheet.Cells(LvXStart, 9).Value2=nextCondition
-- 		LevelSheet.Cells(LvXStart, 10).Value2=drop
-- 		LevelSheet.Cells(LvXStart, 13).Value2=awakeCondition
-- 		LevelSheet.Cells(LvXStart, 14).Value2=awakeReward

-- 		LvXStart=LvXStart+1

-- end

-- local MonsterXStart=6

-- function FullOneMonster(mid,hp,isBox,reword)


-- 	MonsterSheet.Cells(MonsterXStart, 1).Value2="DATA"
-- 	MonsterSheet.Cells(MonsterXStart, 4).Value2=mid
-- 	local perfab="monster"
-- 	local isBoxBool=false
-- 	if isBox==nil then

-- 	else
-- 		perfab="box"
-- 		isBoxBool=true
-- 	end
-- 	MonsterSheet.Cells(MonsterXStart, 5).Value2=perfab
-- 	MonsterSheet.Cells(MonsterXStart, 7).Value2=hp
-- 	if reword==nil then

-- 	else
-- 		MonsterSheet.Cells(MonsterXStart, 8).Value2=reword
-- 	end
-- 	MonsterXStart=MonsterXStart+1
-- 	return isBoxBool
-- end


-- local Y=6
-- local mId=1
-- while(true) do
-- 	local levelId= DATASheet.Cells(2, Y).Value2
-- 	local reword= DATASheet.Cells(6, Y).Value2
-- 	local awakeCondition=DATASheet.Cells(3, Y+1).Value2
-- 	print("-----------level:Y",Y)
-- 	local awakeReward="{base_power="..DATASheet.Cells(3, Y+2).Value2.."}"
-- 	local drop="{base_wins="..DATASheet.Cells(6, Y).Value2.."}"
-- 	local key=DATASheet.Cells(4, Y+3).Value2
-- 	local nextCondition="{base_pwer=1000000000000000000000}"
-- 	if key then
-- 		nextCondition="{"..key.."="..DATASheet.Cells(5, Y+3).Value2.."}"
-- 	end  

-- 	local y=Y
-- 	local x=7
-- 	local monster={}
-- 	local boxCount=0
-- 	while(true) do
-- 		local hp=DATASheet.Cells(x,y).Value2
-- 		local isBox=DATASheet.Cells(x,y+1).Value2
-- 		local reword=DATASheet.Cells(x,y+2).Value2
-- 		if hp==nil then
-- 			break
-- 		end
-- 		print("mId:",mId)
-- 		if FullOneMonster(mId,hp,isBox,reword) then
-- 			boxCount=boxCount+1
-- 		end
-- 		table.insert(monster,mId)
-- 		x=x+1
-- 		mId=mId+1
-- 	end

-- 	Y=Y+3

-- 	FullOneLevel(levelId,reword,awakeCondition,awakeReward,drop,nextCondition,monster,boxCount)

-- 	if key==nil or key=="" then
-- 		break
-- 	end

-- end


-- LevelSheet.Cells(LvXStart+2, 1).Value2="CLOSE"
-- MonsterSheet.Cells(MonsterXStart+2, 1).Value2="CLOSE"



book:Save()
book:Close()

excel.DisplayAlerts = false
excel:Quit()